package br.ufpb.di.knowledgetv.sqtv.services;

import java.util.List;

import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import org.apache.log4j.Logger;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Resource;
import org.springframework.beans.factory.BeanNameAware;

public abstract class AbstractService implements BeanNameAware {

    Logger logger = Logger.getLogger(AbstractService.class);
    protected String beanName;

	public abstract List<Resource> searchByKeyword(String keyword);
    public abstract Model getModel(String url);

    public static OntModel accessObject(String uri) {
        OntModel result = ModelFactory.createOntologyModel();
        result.read(uri);
        return result;
    }

    public static OntModel enhanceObjectByURI(String uri) {
        Model result = ModelFactory.createDefaultModel();
        result.read(uri);
        OntModelSpec oms = new OntModelSpec(OntModelSpec.OWL_MEM_RDFS_INF);
        OntModel infered = ModelFactory.createOntologyModel(oms, result);
        return infered;
    }

    protected Resource verifyExistance(Resource r, List<Resource> list) {
        for (Resource resourceInResults : list) {
            if(resourceInResults.getURI().equals(r.getURI())) {
                return resourceInResults;
            }
        }
        return null;
    }

}
